
#pragma once
#include "cv.h"
#include "highgui.h"
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <math.h>
#include <stdlib.h>
#include "settings.h"
#include "Ident.h"
#include "Servo.h"
#include "Adjustments.h"
#include <string>
#include "one.h"

#pragma region image
IplImage* rez=0;
IplImage* rez2=0;
IplImage* img2 = 0;

CvCapture* capture = 0;
CvCapture* capture3 = 0;
CvSize size1 = cvSize(640,480); 
CvSize size2 = cvSize(180,150); 
IplImage* img=cvCreateImage(size1,8,3);
IplImage* img4=cvCreateImage(size2,8,3);
IplImage*   split = cvCreateImage (size1, IPL_DEPTH_8U, 1); 
IplImage* img7=cvCreateImage(size2,8,3);

CvRect track_windowf;
CvBox2D track_boxf;
CvConnectedComp track_compf;

#pragma endregion
#pragma region variables
int choice=1;
int port=0;
bool flag3_=0;
int countdown_=20;
bool stopt_=0;
int countdown2_=0;

int speedchoice_=1;
int trigchoice_=1;
double factorx_=1;
double factory_=1;
int addtoY=0;
int bullet_=100;
int decrease_=0;
bool ident_=0;
int trigra1_=170;
int trigra2_=220;

int securitychoice=1;
int waitth3_=0;

int threshold1=100;

int colr=0;

int camp1_=0;
int camp2_=1;
int times=0;
int min_=20;
int max_=35;
int bounds_=35;
int blobnr=0;
int tracx=0;
int tracy=0;
int tracker=1;
int found=0;
bool flag_=0;
int iii=0;
int servnrx_=1;
int servnry_=2;
int servnrt_=3;
int recwidth;
int recheight;
int offset1=0;
int offset2=0;
bool trig_=0;
bool go_=0;
int tracker_=0;
int backp_=0;
int vmi_=20;
int vma_=220;
int smi_=40;
int progress_=0;
double scale1=1;
double scale2=1;
float width_=0;
float height_=0;
CvSize size;
CvSeq* contours = 0;
int motion_=0;

int top_=0;
int bot_=0;
int left_=0;
int right_=0;

int drawx_=0;
int drawy_=0;

int xrect=0;
int yrect=0;
int xrect2=0;
int yrect2=0;
int bl; 
CvRect rect2;
CvRect rect3;
CvRect rect1[50];
CvPoint cent1[50]; 
int *p=&bl;
int j;
int i=0;
CvRect* rect=&rect1[0];
CvPoint* cent=&cent1[0];
int perim_=4;
volatile int show_=1;

#pragma endregion


namespace Turret {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;
	using namespace std;
	using namespace System::Threading;


	
	public ref class Form1 : public System::Windows::Forms::Form
	{
	




	public: String^ nr;
				
	public:
		Form1(void)
		{
			
			InitializeComponent();
			th1 = gcnew Thread(gcnew ThreadStart(this, &Form1::th1Method)); //main thread
            th2 = gcnew Thread(gcnew ThreadStart(this, &Form1::th2Method)); //servo thread
			th3 = gcnew Thread(gcnew ThreadStart(this, &Form1::th3Method)); //security camera
            
			//th1->Priority=ThreadPriority::AboveNormal;
			//th2->Priority=ThreadPriority::Normal;
			th1->Start();
            th2->Start();
			th3->Start();
			th1->Suspend();
		    th2->Suspend();
			th3->Suspend();
            serialPort1->Open();
			iii=0;
		
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
    ~Form1()
	{
	if (components)
	{
	delete components;
	}
	
    th1->Abort();
    th2->Abort();
	    th3->Abort();
    cvReleaseImage(&img); 
	cvReleaseImage(&rez); 
	cvReleaseImage(&rez2); 
	cvReleaseImage(&img2); 
	cvReleaseImage(&img7);
	cvReleaseImage(&img4);
	cvReleaseImage(&split); 
	cvReleaseCapture(&capture);
	cvReleaseCapture(&capture3);
	serialPort1->Close();
    }
	private: System::Windows::Forms::PictureBox^  pictureBox1;
	protected: 
	private: System::Windows::Forms::CheckBox^  checkBox1;


	private: System::Windows::Forms::Label^  label8;
	private: System::Windows::Forms::Label^  label9;
	private: System::Windows::Forms::Label^  label10;
	private: System::Windows::Forms::Label^  label11;
	private: System::Windows::Forms::Label^  label12;






	private: System::Windows::Forms::Button^  button6;
	private: System::Windows::Forms::Label^  label21;
	private: System::Windows::Forms::Label^  label22;
	private: System::Windows::Forms::NumericUpDown^  numericUpDown7;
	private: System::Windows::Forms::Button^  button8;
	private: System::Windows::Forms::Button^  button9;
	private: System::Windows::Forms::GroupBox^  groupBox2;

	private: System::Windows::Forms::Label^  label20;
	private: System::Windows::Forms::GroupBox^  STATISTICS;
	private: System::Windows::Forms::Label^  label30;
	private: System::Windows::Forms::Label^  label32;
	private: System::Windows::Forms::NumericUpDown^  numericUpDown10;
    private: System::Windows::Forms::Label^  label33;
    private: System::IO::Ports::SerialPort^  serialPort1;
    private: System::Windows::Forms::ComboBox^  comboBox1;
    private: System::Windows::Forms::Label^  label13;  
    private: System::Windows::Forms::ComboBox^  comboBox2;
    private: System::Windows::Forms::MenuStrip^  menuStrip1;
    private: System::Windows::Forms::ToolStripMenuItem^  settingsToolStripMenuItem;
    private: System::Windows::Forms::ToolStripMenuItem^  dataToolStripMenuItem;
    private: System::Windows::Forms::ToolStripMenuItem^  enterDataToolStripMenuItem;
    private: System::Windows::Forms::ToolStripMenuItem^  changeSettingsToolStripMenuItem;
    private: System::Windows::Forms::GroupBox^  groupBox1;
    private: System::Windows::Forms::PictureBox^  pictureBox3;
    private: System::Windows::Forms::Label^  label7;
    private: System::Windows::Forms::Label^  label6;
    private: System::Windows::Forms::Label^  label5;
    private: System::Windows::Forms::Label^  label3;
    private: System::Windows::Forms::Label^  label1;
    private: System::Windows::Forms::Label^  label14;

	private: System::Windows::Forms::GroupBox^  groupBox3;


	private: System::ComponentModel::IContainer^  components;
 
	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>
   
private: System::Windows::Forms::CheckBox^  checkBox3;
private: System::Windows::Forms::ToolStripMenuItem^  servoSetupToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^  setupToolStripMenuItem;
		 Thread ^th1;
private: System::Windows::Forms::Splitter^  splitter1;
private: System::Windows::Forms::GroupBox^  groupBox6;
private: System::Windows::Forms::GroupBox^  groupBox4;
private: System::Windows::Forms::GroupBox^  groupBox7;
private: System::Windows::Forms::PictureBox^  pictureBox2;
private: System::Windows::Forms::Button^  button1;
private: System::Windows::Forms::CheckBox^  checkBox4;
private: System::Windows::Forms::ProgressBar^  progressBar1;
private: System::Windows::Forms::Label^  label23;
private: System::Windows::Forms::Label^  label24;
private: System::Windows::Forms::CheckBox^  checkBox5;
private: System::Windows::Forms::Label^  label25;
private: System::Windows::Forms::ComboBox^  comboBox3;
private: System::Windows::Forms::Label^  label29;
private: System::Windows::Forms::Label^  label28;
private: System::Windows::Forms::Label^  label27;
private: System::Windows::Forms::Label^  label26;
private: System::Windows::Forms::Label^  label31;
private: System::Windows::Forms::ComboBox^  comboBox4;
private: System::Windows::Forms::Button^  button3;
private: System::Windows::Forms::Button^  button2;
private: System::Windows::Forms::Label^  label34;

private: System::Windows::Forms::Button^  button4;

private: System::Windows::Forms::Button^  button7;
private: System::Windows::Forms::Button^  button5;
private: System::Windows::Forms::NumericUpDown^  numericUpDown1;
private: System::Windows::Forms::NumericUpDown^  numericUpDown2;
private: System::Windows::Forms::GroupBox^  groupBox5;
private: System::Windows::Forms::Label^  label40;
private: System::Windows::Forms::Label^  label39;
private: System::Windows::Forms::Label^  label38;
private: System::Windows::Forms::Label^  label37;
private: System::Windows::Forms::Label^  label36;
private: System::Windows::Forms::Label^  label35;

private: System::Windows::Forms::Label^  label42;
private: System::Windows::Forms::Label^  label45;
private: System::Windows::Forms::Label^  label44;
private: System::Windows::Forms::Label^  label43;
private: System::Windows::Forms::CheckBox^  checkBox6;
private: System::Windows::Forms::ToolStripMenuItem^  aToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^  forVelocityaccelerationdistanceToolStripMenuItem;
private: System::Windows::Forms::Button^  button10;
private: System::Windows::Forms::Label^  label46;
private: System::Windows::Forms::Label^  label41;
private: System::Windows::Forms::Button^  button11;
private: System::Windows::Forms::NumericUpDown^  numericUpDown4;
private: System::Windows::Forms::Label^  label4;
private: System::Windows::Forms::NumericUpDown^  numericUpDown3;
private: System::Windows::Forms::Label^  label2;
private: System::Windows::Forms::NumericUpDown^  numericUpDown5;
private: System::Windows::Forms::Label^  label15;
private: System::Windows::Forms::Label^  label16;
private: System::Windows::Forms::ComboBox^  comboBox5;




		 Thread ^th2;
private: System::Windows::Forms::Button^  button12;
private: System::Windows::Forms::Button^  button13;
private: System::Windows::Forms::Label^  label18;
private: System::Windows::Forms::Label^  label17;
		 Thread ^th3;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
			this->components = (gcnew System::ComponentModel::Container());
			System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid));
			this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox());
			this->checkBox1 = (gcnew System::Windows::Forms::CheckBox());
			this->label8 = (gcnew System::Windows::Forms::Label());
			this->label9 = (gcnew System::Windows::Forms::Label());
			this->label10 = (gcnew System::Windows::Forms::Label());
			this->label11 = (gcnew System::Windows::Forms::Label());
			this->label12 = (gcnew System::Windows::Forms::Label());
			this->button6 = (gcnew System::Windows::Forms::Button());
			this->label21 = (gcnew System::Windows::Forms::Label());
			this->label22 = (gcnew System::Windows::Forms::Label());
			this->numericUpDown7 = (gcnew System::Windows::Forms::NumericUpDown());
			this->button8 = (gcnew System::Windows::Forms::Button());
			this->button9 = (gcnew System::Windows::Forms::Button());
			this->groupBox2 = (gcnew System::Windows::Forms::GroupBox());
			this->button12 = (gcnew System::Windows::Forms::Button());
			this->button13 = (gcnew System::Windows::Forms::Button());
			this->comboBox5 = (gcnew System::Windows::Forms::ComboBox());
			this->label16 = (gcnew System::Windows::Forms::Label());
			this->button11 = (gcnew System::Windows::Forms::Button());
			this->button1 = (gcnew System::Windows::Forms::Button());
			this->checkBox6 = (gcnew System::Windows::Forms::CheckBox());
			this->checkBox4 = (gcnew System::Windows::Forms::CheckBox());
			this->label31 = (gcnew System::Windows::Forms::Label());
			this->comboBox4 = (gcnew System::Windows::Forms::ComboBox());
			this->label24 = (gcnew System::Windows::Forms::Label());
			this->progressBar1 = (gcnew System::Windows::Forms::ProgressBar());
			this->checkBox5 = (gcnew System::Windows::Forms::CheckBox());
			this->label25 = (gcnew System::Windows::Forms::Label());
			this->comboBox3 = (gcnew System::Windows::Forms::ComboBox());
			this->label23 = (gcnew System::Windows::Forms::Label());
			this->checkBox3 = (gcnew System::Windows::Forms::CheckBox());
			this->label13 = (gcnew System::Windows::Forms::Label());
			this->comboBox2 = (gcnew System::Windows::Forms::ComboBox());
			this->comboBox1 = (gcnew System::Windows::Forms::ComboBox());
			this->label20 = (gcnew System::Windows::Forms::Label());
			this->STATISTICS = (gcnew System::Windows::Forms::GroupBox());
			this->label46 = (gcnew System::Windows::Forms::Label());
			this->label41 = (gcnew System::Windows::Forms::Label());
			this->label45 = (gcnew System::Windows::Forms::Label());
			this->label44 = (gcnew System::Windows::Forms::Label());
			this->label43 = (gcnew System::Windows::Forms::Label());
			this->label42 = (gcnew System::Windows::Forms::Label());
			this->label29 = (gcnew System::Windows::Forms::Label());
			this->label28 = (gcnew System::Windows::Forms::Label());
			this->label27 = (gcnew System::Windows::Forms::Label());
			this->label26 = (gcnew System::Windows::Forms::Label());
			this->label33 = (gcnew System::Windows::Forms::Label());
			this->label30 = (gcnew System::Windows::Forms::Label());
			this->label32 = (gcnew System::Windows::Forms::Label());
			this->numericUpDown10 = (gcnew System::Windows::Forms::NumericUpDown());
			this->serialPort1 = (gcnew System::IO::Ports::SerialPort(this->components));
			this->menuStrip1 = (gcnew System::Windows::Forms::MenuStrip());
			this->settingsToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
			this->changeSettingsToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
			this->dataToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
			this->enterDataToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
			this->servoSetupToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
			this->setupToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
			this->aToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
			this->forVelocityaccelerationdistanceToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
			this->groupBox1 = (gcnew System::Windows::Forms::GroupBox());
			this->label18 = (gcnew System::Windows::Forms::Label());
			this->label17 = (gcnew System::Windows::Forms::Label());
			this->pictureBox3 = (gcnew System::Windows::Forms::PictureBox());
			this->label14 = (gcnew System::Windows::Forms::Label());
			this->label7 = (gcnew System::Windows::Forms::Label());
			this->label6 = (gcnew System::Windows::Forms::Label());
			this->label5 = (gcnew System::Windows::Forms::Label());
			this->label3 = (gcnew System::Windows::Forms::Label());
			this->label1 = (gcnew System::Windows::Forms::Label());
			this->groupBox3 = (gcnew System::Windows::Forms::GroupBox());
			this->splitter1 = (gcnew System::Windows::Forms::Splitter());
			this->groupBox6 = (gcnew System::Windows::Forms::GroupBox());
			this->numericUpDown5 = (gcnew System::Windows::Forms::NumericUpDown());
			this->label15 = (gcnew System::Windows::Forms::Label());
			this->numericUpDown4 = (gcnew System::Windows::Forms::NumericUpDown());
			this->label4 = (gcnew System::Windows::Forms::Label());
			this->numericUpDown3 = (gcnew System::Windows::Forms::NumericUpDown());
			this->label2 = (gcnew System::Windows::Forms::Label());
			this->numericUpDown2 = (gcnew System::Windows::Forms::NumericUpDown());
			this->numericUpDown1 = (gcnew System::Windows::Forms::NumericUpDown());
			this->button7 = (gcnew System::Windows::Forms::Button());
			this->button5 = (gcnew System::Windows::Forms::Button());
			this->button4 = (gcnew System::Windows::Forms::Button());
			this->label34 = (gcnew System::Windows::Forms::Label());
			this->button3 = (gcnew System::Windows::Forms::Button());
			this->button2 = (gcnew System::Windows::Forms::Button());
			this->groupBox4 = (gcnew System::Windows::Forms::GroupBox());
			this->groupBox7 = (gcnew System::Windows::Forms::GroupBox());
			this->pictureBox2 = (gcnew System::Windows::Forms::PictureBox());
			this->groupBox5 = (gcnew System::Windows::Forms::GroupBox());
			this->button10 = (gcnew System::Windows::Forms::Button());
			this->label40 = (gcnew System::Windows::Forms::Label());
			this->label39 = (gcnew System::Windows::Forms::Label());
			this->label38 = (gcnew System::Windows::Forms::Label());
			this->label37 = (gcnew System::Windows::Forms::Label());
			this->label36 = (gcnew System::Windows::Forms::Label());
			this->label35 = (gcnew System::Windows::Forms::Label());
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox1))->BeginInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->numericUpDown7))->BeginInit();
			this->groupBox2->SuspendLayout();
			this->STATISTICS->SuspendLayout();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->numericUpDown10))->BeginInit();
			this->menuStrip1->SuspendLayout();
			this->groupBox1->SuspendLayout();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox3))->BeginInit();
			this->groupBox3->SuspendLayout();
			this->groupBox6->SuspendLayout();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->numericUpDown5))->BeginInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->numericUpDown4))->BeginInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->numericUpDown3))->BeginInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->numericUpDown2))->BeginInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->numericUpDown1))->BeginInit();
			this->groupBox4->SuspendLayout();
			this->groupBox7->SuspendLayout();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox2))->BeginInit();
			this->groupBox5->SuspendLayout();
			this->SuspendLayout();
			// 
			// pictureBox1
			// 
			this->pictureBox1->BackgroundImageLayout = System::Windows::Forms::ImageLayout::Center;
			this->pictureBox1->Location = System::Drawing::Point(9, 19);
			this->pictureBox1->Name = L"pictureBox1";
			this->pictureBox1->Size = System::Drawing::Size(640, 480);
			this->pictureBox1->TabIndex = 0;
			this->pictureBox1->TabStop = false;
			this->pictureBox1->MouseMove += gcnew System::Windows::Forms::MouseEventHandler(this, &Form1::pictureBox1_Mouse_Move);
			this->pictureBox1->MouseDown += gcnew System::Windows::Forms::MouseEventHandler(this, &Form1::pictureBox1_Mouse_Down);
			// 
			// checkBox1
			// 
			this->checkBox1->AutoSize = true;
			this->checkBox1->Location = System::Drawing::Point(122, 27);
			this->checkBox1->Name = L"checkBox1";
			this->checkBox1->Size = System::Drawing::Size(82, 17);
			this->checkBox1->TabIndex = 6;
			this->checkBox1->Text = L"ShowImage";
			this->checkBox1->UseVisualStyleBackColor = true;
			this->checkBox1->CheckedChanged += gcnew System::EventHandler(this, &Form1::checkBox1_CheckedChanged);
			// 
			// label8
			// 
			this->label8->AutoSize = true;
			this->label8->Location = System::Drawing::Point(6, 16);
			this->label8->Name = L"label8";
			this->label8->Size = System::Drawing::Size(14, 13);
			this->label8->TabIndex = 21;
			this->label8->Text = L"X";
			// 
			// label9
			// 
			this->label9->AutoSize = true;
			this->label9->Location = System::Drawing::Point(6, 36);
			this->label9->Name = L"label9";
			this->label9->Size = System::Drawing::Size(14, 13);
			this->label9->TabIndex = 22;
			this->label9->Text = L"Y";
			// 
			// label10
			// 
			this->label10->AutoSize = true;
			this->label10->Location = System::Drawing::Point(6, 56);
			this->label10->Name = L"label10";
			this->label10->Size = System::Drawing::Size(14, 13);
			this->label10->TabIndex = 23;
			this->label10->Text = L"Z";
			// 
			// label11
			// 
			this->label11->AutoSize = true;
			this->label11->Location = System::Drawing::Point(45, 16);
			this->label11->Name = L"label11";
			this->label11->Size = System::Drawing::Size(16, 13);
			this->label11->TabIndex = 24;
			this->label11->Text = L"...";
			// 
			// label12
			// 
			this->label12->AutoSize = true;
			this->label12->Location = System::Drawing::Point(44, 36);
			this->label12->Name = L"label12";
			this->label12->Size = System::Drawing::Size(16, 13);
			this->label12->TabIndex = 25;
			this->label12->Text = L"...";
			// 
			// button6
			// 
			this->button6->BackColor = System::Drawing::Color::White;
			this->button6->Location = System::Drawing::Point(149, 15);
			this->button6->Name = L"button6";
			this->button6->Size = System::Drawing::Size(63, 45);
			this->button6->TabIndex = 38;
			this->button6->Text = L"Exit";
			this->button6->UseVisualStyleBackColor = false;
			this->button6->Click += gcnew System::EventHandler(this, &Form1::button6_Click);
			// 
			// label21
			// 
			this->label21->AutoSize = true;
			this->label21->Location = System::Drawing::Point(146, 36);
			this->label21->Name = L"label21";
			this->label21->Size = System::Drawing::Size(33, 13);
			this->label21->TabIndex = 40;
			this->label21->Text = L"Blobs";
			// 
			// label22
			// 
			this->label22->AutoSize = true;
			this->label22->Location = System::Drawing::Point(182, 36);
			this->label22->Name = L"label22";
			this->label22->Size = System::Drawing::Size(16, 13);
			this->label22->TabIndex = 41;
			this->label22->Text = L"...";
			// 
			// numericUpDown7
			// 
			this->numericUpDown7->Location = System::Drawing::Point(86, 19);
			this->numericUpDown7->Name = L"numericUpDown7";
			this->numericUpDown7->Size = System::Drawing::Size(55, 20);
			this->numericUpDown7->TabIndex = 42;
			this->numericUpDown7->Value = System::Decimal(gcnew cli::array< System::Int32 >(4) {1, 0, 0, 0});
			this->numericUpDown7->ValueChanged += gcnew System::EventHandler(this, &Form1::numericUpDown7_ValueChanged);
			// 
			// button8
			// 
			this->button8->BackColor = System::Drawing::Color::White;
			this->button8->Location = System::Drawing::Point(79, 15);
			this->button8->Name = L"button8";
			this->button8->Size = System::Drawing::Size(63, 45);
			this->button8->TabIndex = 54;
			this->button8->Text = L"Pause";
			this->button8->UseVisualStyleBackColor = false;
			this->button8->Click += gcnew System::EventHandler(this, &Form1::button8_Click);
			// 
			// button9
			// 
			this->button9->BackColor = System::Drawing::Color::White;
			this->button9->Location = System::Drawing::Point(9, 15);
			this->button9->Name = L"button9";
			this->button9->Size = System::Drawing::Size(63, 45);
			this->button9->TabIndex = 55;
			this->button9->Text = L"Start";
			this->button9->UseVisualStyleBackColor = false;
			this->button9->Click += gcnew System::EventHandler(this, &Form1::button9_Click);
			// 
			// groupBox2
			// 
			this->groupBox2->BackColor = System::Drawing::Color::Gainsboro;
			this->groupBox2->Controls->Add(this->button12);
			this->groupBox2->Controls->Add(this->button13);
			this->groupBox2->Controls->Add(this->comboBox5);
			this->groupBox2->Controls->Add(this->label16);
			this->groupBox2->Controls->Add(this->button11);
			this->groupBox2->Controls->Add(this->button1);
			this->groupBox2->Controls->Add(this->checkBox6);
			this->groupBox2->Controls->Add(this->checkBox4);
			this->groupBox2->Controls->Add(this->label31);
			this->groupBox2->Controls->Add(this->comboBox4);
			this->groupBox2->Controls->Add(this->label24);
			this->groupBox2->Controls->Add(this->progressBar1);
			this->groupBox2->Controls->Add(this->checkBox5);
			this->groupBox2->Controls->Add(this->label25);
			this->groupBox2->Controls->Add(this->comboBox3);
			this->groupBox2->Controls->Add(this->label23);
			this->groupBox2->Controls->Add(this->checkBox3);
			this->groupBox2->Controls->Add(this->label13);
			this->groupBox2->Controls->Add(this->comboBox2);
			this->groupBox2->Controls->Add(this->comboBox1);
			this->groupBox2->Controls->Add(this->label20);
			this->groupBox2->Controls->Add(this->checkBox1);
			this->groupBox2->Location = System::Drawing::Point(676, 108);
			this->groupBox2->Name = L"groupBox2";
			this->groupBox2->Size = System::Drawing::Size(222, 302);
			this->groupBox2->TabIndex = 57;
			this->groupBox2->TabStop = false;
			this->groupBox2->Text = L"DETECTOR";
			this->groupBox2->Enter += gcnew System::EventHandler(this, &Form1::groupBox2_Enter);
			// 
			// button12
			// 
			this->button12->Location = System::Drawing::Point(122, 185);
			this->button12->Name = L"button12";
			this->button12->Size = System::Drawing::Size(42, 23);
			this->button12->TabIndex = 1;
			this->button12->Text = L"Start";
			this->button12->UseVisualStyleBackColor = true;
			this->button12->Click += gcnew System::EventHandler(this, &Form1::button12_Click);
			// 
			// button13
			// 
			this->button13->Location = System::Drawing::Point(170, 185);
			this->button13->Name = L"button13";
			this->button13->Size = System::Drawing::Size(42, 23);
			this->button13->TabIndex = 2;
			this->button13->Text = L"Stop";
			this->button13->UseVisualStyleBackColor = true;
			this->button13->Click += gcnew System::EventHandler(this, &Form1::button13_Click);
			// 
			// comboBox5
			// 
			this->comboBox5->FormattingEnabled = true;
			this->comboBox5->Items->AddRange(gcnew cli::array< System::Object^  >(2) {L"Barcode", L"Face"});
			this->comboBox5->Location = System::Drawing::Point(9, 187);
			this->comboBox5->Name = L"comboBox5";
			this->comboBox5->Size = System::Drawing::Size(102, 21);
			this->comboBox5->TabIndex = 73;
			this->comboBox5->SelectedIndexChanged += gcnew System::EventHandler(this, &Form1::comboBox5_SelectedIndexChanged);
			// 
			// label16
			// 
			this->label16->AutoSize = true;
			this->label16->Location = System::Drawing::Point(6, 171);
			this->label16->Name = L"label16";
			this->label16->Size = System::Drawing::Size(88, 13);
			this->label16->TabIndex = 72;
			this->label16->Text = L"Security Scanner";
			// 
			// button11
			// 
			this->button11->Location = System::Drawing::Point(122, 266);
			this->button11->Name = L"button11";
			this->button11->Size = System::Drawing::Size(95, 23);
			this->button11->TabIndex = 1;
			this->button11->Text = L"Rescan";
			this->button11->UseVisualStyleBackColor = true;
			this->button11->Click += gcnew System::EventHandler(this, &Form1::button11_Click);
			// 
			// button1
			// 
			this->button1->BackColor = System::Drawing::Color::White;
			this->button1->Location = System::Drawing::Point(9, 228);
			this->button1->Name = L"button1";
			this->button1->Size = System::Drawing::Size(102, 21);
			this->button1->TabIndex = 1;
			this->button1->Text = L"FollowBlob";
			this->button1->UseVisualStyleBackColor = false;
			this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
			// 
			// checkBox6
			// 
			this->checkBox6->AutoSize = true;
			this->checkBox6->Location = System::Drawing::Point(122, 147);
			this->checkBox6->Name = L"checkBox6";
			this->checkBox6->Size = System::Drawing::Size(98, 17);
			this->checkBox6->TabIndex = 1;
			this->checkBox6->Text = L"Leading Target";
			this->checkBox6->UseVisualStyleBackColor = true;
			// 
			// checkBox4
			// 
			this->checkBox4->AutoSize = true;
			this->checkBox4->Location = System::Drawing::Point(122, 228);
			this->checkBox4->Name = L"checkBox4";
			this->checkBox4->Size = System::Drawing::Size(81, 17);
			this->checkBox4->TabIndex = 67;
			this->checkBox4->Text = L"MeanTrack";
			this->checkBox4->UseVisualStyleBackColor = true;
			this->checkBox4->CheckedChanged += gcnew System::EventHandler(this, &Form1::checkBox4_CheckedChanged);
			// 
			// label31
			// 
			this->label31->AutoSize = true;
			this->label31->Location = System::Drawing::Point(6, 131);
			this->label31->Name = L"label31";
			this->label31->Size = System::Drawing::Size(38, 13);
			this->label31->TabIndex = 71;
			this->label31->Text = L"Speed";
			// 
			// comboBox4
			// 
			this->comboBox4->FormattingEnabled = true;
			this->comboBox4->Items->AddRange(gcnew cli::array< System::Object^  >(3) {L"Slow", L"Medium", L"Fast"});
			this->comboBox4->Location = System::Drawing::Point(9, 147);
			this->comboBox4->Name = L"comboBox4";
			this->comboBox4->Size = System::Drawing::Size(102, 21);
			this->comboBox4->TabIndex = 1;
			this->comboBox4->SelectedIndexChanged += gcnew System::EventHandler(this, &Form1::comboBox4_SelectedIndexChanged);
			// 
			// label24
			// 
			this->label24->AutoSize = true;
			this->label24->Location = System::Drawing::Point(7, 211);
			this->label24->Name = L"label24";
			this->label24->Size = System::Drawing::Size(71, 13);
			this->label24->TabIndex = 1;
			this->label24->Text = L"MeanTracker";
			// 
			// progressBar1
			// 
			this->progressBar1->Location = System::Drawing::Point(9, 268);
			this->progressBar1->Maximum = 303;
			this->progressBar1->Name = L"progressBar1";
			this->progressBar1->Size = System::Drawing::Size(102, 21);
			this->progressBar1->TabIndex = 1;
			// 
			// checkBox5
			// 
			this->checkBox5->AutoSize = true;
			this->checkBox5->Location = System::Drawing::Point(122, 107);
			this->checkBox5->Name = L"checkBox5";
			this->checkBox5->Size = System::Drawing::Size(76, 17);
			this->checkBox5->TabIndex = 70;
			this->checkBox5->Text = L"Trigger On";
			this->checkBox5->UseVisualStyleBackColor = true;
			// 
			// label25
			// 
			this->label25->AutoSize = true;
			this->label25->Location = System::Drawing::Point(6, 91);
			this->label25->Name = L"label25";
			this->label25->Size = System::Drawing::Size(40, 13);
			this->label25->TabIndex = 69;
			this->label25->Text = L"Trigger";
			// 
			// comboBox3
			// 
			this->comboBox3->FormattingEnabled = true;
			this->comboBox3->Items->AddRange(gcnew cli::array< System::Object^  >(4) {L"Mouse", L"Burst", L"Rapid", L"Hold"});
			this->comboBox3->Location = System::Drawing::Point(9, 107);
			this->comboBox3->Name = L"comboBox3";
			this->comboBox3->Size = System::Drawing::Size(102, 21);
			this->comboBox3->TabIndex = 68;
			this->comboBox3->SelectedIndexChanged += gcnew System::EventHandler(this, &Form1::comboBox3_SelectedIndexChanged);
			// 
			// label23
			// 
			this->label23->AutoSize = true;
			this->label23->Location = System::Drawing::Point(6, 252);
			this->label23->Name = L"label23";
			this->label23->Size = System::Drawing::Size(105, 13);
			this->label23->TabIndex = 1;
			this->label23->Text = L"BackgroundScanner";
			// 
			// checkBox3
			// 
			this->checkBox3->AutoSize = true;
			this->checkBox3->Location = System::Drawing::Point(122, 67);
			this->checkBox3->Name = L"checkBox3";
			this->checkBox3->Size = System::Drawing::Size(76, 17);
			this->checkBox3->TabIndex = 66;
			this->checkBox3->Text = L"Servos On";
			this->checkBox3->UseVisualStyleBackColor = true;
			// 
			// label13
			// 
			this->label13->AutoSize = true;
			this->label13->Location = System::Drawing::Point(6, 51);
			this->label13->Name = L"label13";
			this->label13->Size = System::Drawing::Size(44, 13);
			this->label13->TabIndex = 65;
			this->label13->Text = L"Tracker";
			// 
			// comboBox2
			// 
			this->comboBox2->FormattingEnabled = true;
			this->comboBox2->Items->AddRange(gcnew cli::array< System::Object^  >(4) {L"Biggest", L"Smallest", L"Follow", L"Random"});
			this->comboBox2->Location = System::Drawing::Point(9, 67);
			this->comboBox2->Name = L"comboBox2";
			this->comboBox2->Size = System::Drawing::Size(102, 21);
			this->comboBox2->TabIndex = 64;
			this->comboBox2->SelectedIndexChanged += gcnew System::EventHandler(this, &Form1::comboBox2_SelectedIndexChanged);
			// 
			// comboBox1
			// 
			this->comboBox1->FormattingEnabled = true;
			this->comboBox1->Items->AddRange(gcnew cli::array< System::Object^  >(5) {L"MotionDifference", L"MotionBackground", L"ColourHist", 
				L"Mouse", L"People"});
			this->comboBox1->Location = System::Drawing::Point(9, 27);
			this->comboBox1->Name = L"comboBox1";
			this->comboBox1->Size = System::Drawing::Size(102, 21);
			this->comboBox1->TabIndex = 63;
			this->comboBox1->SelectedIndexChanged += gcnew System::EventHandler(this, &Form1::comboBox1_SelectedIndexChanged);
			// 
			// label20
			// 
			this->label20->AutoSize = true;
			this->label20->Location = System::Drawing::Point(6, 11);
			this->label20->Name = L"label20";
			this->label20->Size = System::Drawing::Size(48, 13);
			this->label20->TabIndex = 57;
			this->label20->Text = L"Detector";
			// 
			// STATISTICS
			// 
			this->STATISTICS->BackColor = System::Drawing::Color::Gainsboro;
			this->STATISTICS->Controls->Add(this->label46);
			this->STATISTICS->Controls->Add(this->label41);
			this->STATISTICS->Controls->Add(this->label45);
			this->STATISTICS->Controls->Add(this->label44);
			this->STATISTICS->Controls->Add(this->label43);
			this->STATISTICS->Controls->Add(this->label42);
			this->STATISTICS->Controls->Add(this->label29);
			this->STATISTICS->Controls->Add(this->label28);
			this->STATISTICS->Controls->Add(this->label27);
			this->STATISTICS->Controls->Add(this->label26);
			this->STATISTICS->Controls->Add(this->label33);
			this->STATISTICS->Controls->Add(this->label8);
			this->STATISTICS->Controls->Add(this->label11);
			this->STATISTICS->Controls->Add(this->label9);
			this->STATISTICS->Controls->Add(this->label12);
			this->STATISTICS->Controls->Add(this->label22);
			this->STATISTICS->Controls->Add(this->label10);
			this->STATISTICS->Controls->Add(this->label21);
			this->STATISTICS->Location = System::Drawing::Point(677, 416);
			this->STATISTICS->Name = L"STATISTICS";
			this->STATISTICS->Size = System::Drawing::Size(221, 77);
			this->STATISTICS->TabIndex = 58;
			this->STATISTICS->TabStop = false;
			this->STATISTICS->Text = L"STATISTICS";
			this->STATISTICS->Enter += gcnew System::EventHandler(this, &Form1::groupBox3_Enter);
			// 
			// label46
			// 
			this->label46->AutoSize = true;
			this->label46->Location = System::Drawing::Point(182, 16);
			this->label46->Name = L"label46";
			this->label46->Size = System::Drawing::Size(16, 13);
			this->label46->TabIndex = 71;
			this->label46->Text = L"...";
			// 
			// label41
			// 
			this->label41->AutoSize = true;
			this->label41->Location = System::Drawing::Point(146, 16);
			this->label41->Name = L"label41";
			this->label41->Size = System::Drawing::Size(34, 13);
			this->label41->TabIndex = 1;
			this->label41->Text = L"Shots";
			// 
			// label45
			// 
			this->label45->AutoSize = true;
			this->label45->Location = System::Drawing::Point(182, 56);
			this->label45->Name = L"label45";
			this->label45->Size = System::Drawing::Size(16, 13);
			this->label45->TabIndex = 70;
			this->label45->Text = L"...";
			// 
			// label44
			// 
			this->label44->AutoSize = true;
			this->label44->Location = System::Drawing::Point(114, 56);
			this->label44->Name = L"label44";
			this->label44->Size = System::Drawing::Size(16, 13);
			this->label44->TabIndex = 69;
			this->label44->Text = L"...";
			// 
			// label43
			// 
			this->label43->AutoSize = true;
			this->label43->Location = System::Drawing::Point(146, 56);
			this->label43->Name = L"label43";
			this->label43->Size = System::Drawing::Size(21, 13);
			this->label43->TabIndex = 68;
			this->label43->Text = L"AY";
			// 
			// label42
			// 
			this->label42->AutoSize = true;
			this->label42->Location = System::Drawing::Point(78, 56);
			this->label42->Name = L"label42";
			this->label42->Size = System::Drawing::Size(21, 13);
			this->label42->TabIndex = 67;
			this->label42->Text = L"AX";
			// 
			// label29
			// 
			this->label29->AutoSize = true;
			this->label29->Location = System::Drawing::Point(114, 16);
			this->label29->Name = L"label29";
			this->label29->Size = System::Drawing::Size(16, 13);
			this->label29->TabIndex = 66;
			this->label29->Text = L"...";
			// 
			// label28
			// 
			this->label28->AutoSize = true;
			this->label28->Location = System::Drawing::Point(78, 36);
			this->label28->Name = L"label28";
			this->label28->Size = System::Drawing::Size(21, 13);
			this->label28->TabIndex = 65;
			this->label28->Text = L"VY";
			// 
			// label27
			// 
			this->label27->AutoSize = true;
			this->label27->Location = System::Drawing::Point(114, 36);
			this->label27->Name = L"label27";
			this->label27->Size = System::Drawing::Size(16, 13);
			this->label27->TabIndex = 64;
			this->label27->Text = L"...";
			// 
			// label26
			// 
			this->label26->AutoSize = true;
			this->label26->Location = System::Drawing::Point(78, 16);
			this->label26->Name = L"label26";
			this->label26->Size = System::Drawing::Size(21, 13);
			this->label26->TabIndex = 1;
			this->label26->Text = L"VX";
			// 
			// label33
			// 
			this->label33->AutoSize = true;
			this->label33->Location = System::Drawing::Point(45, 56);
			this->label33->Name = L"label33";
			this->label33->Size = System::Drawing::Size(16, 13);
			this->label33->TabIndex = 63;
			this->label33->Text = L"...";
			// 
			// label30
			// 
			this->label30->AutoSize = true;
			this->label30->Location = System::Drawing::Point(6, 23);
			this->label30->Name = L"label30";
			this->label30->Size = System::Drawing::Size(74, 13);
			this->label30->TabIndex = 59;
			this->label30->Text = L"BlobsToTrack";
			// 
			// label32
			// 
			this->label32->AutoSize = true;
			this->label32->Location = System::Drawing::Point(518, 21);
			this->label32->Name = L"label32";
			this->label32->Size = System::Drawing::Size(73, 13);
			this->label32->TabIndex = 61;
			this->label32->Text = L"SwitchToBlob";
			// 
			// numericUpDown10
			// 
			this->numericUpDown10->Location = System::Drawing::Point(597, 16);
			this->numericUpDown10->Name = L"numericUpDown10";
			this->numericUpDown10->Size = System::Drawing::Size(55, 20);
			this->numericUpDown10->TabIndex = 62;
			this->numericUpDown10->ValueChanged += gcnew System::EventHandler(this, &Form1::numericUpDown10_ValueChanged);
			// 
			// menuStrip1
			// 
			this->menuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(4) {this->settingsToolStripMenuItem, 
				this->dataToolStripMenuItem, this->servoSetupToolStripMenuItem, this->aToolStripMenuItem});
			this->menuStrip1->Location = System::Drawing::Point(0, 0);
			this->menuStrip1->Name = L"menuStrip1";
			this->menuStrip1->Size = System::Drawing::Size(905, 24);
			this->menuStrip1->TabIndex = 64;
			this->menuStrip1->Text = L"menuStrip1";
			// 
			// settingsToolStripMenuItem
			// 
			this->settingsToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(1) {this->changeSettingsToolStripMenuItem});
			this->settingsToolStripMenuItem->Name = L"settingsToolStripMenuItem";
			this->settingsToolStripMenuItem->Size = System::Drawing::Size(58, 20);
			this->settingsToolStripMenuItem->Text = L"Settings";
			this->settingsToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::settingsToolStripMenuItem_Click);
			// 
			// changeSettingsToolStripMenuItem
			// 
			this->changeSettingsToolStripMenuItem->Name = L"changeSettingsToolStripMenuItem";
			this->changeSettingsToolStripMenuItem->Size = System::Drawing::Size(164, 22);
			this->changeSettingsToolStripMenuItem->Text = L"Change Settings";
			this->changeSettingsToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::changeSettingsToolStripMenuItem_Click);
			// 
			// dataToolStripMenuItem
			// 
			this->dataToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(1) {this->enterDataToolStripMenuItem});
			this->dataToolStripMenuItem->Name = L"dataToolStripMenuItem";
			this->dataToolStripMenuItem->Size = System::Drawing::Size(82, 20);
			this->dataToolStripMenuItem->Text = L"Identification";
			this->dataToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::dataToolStripMenuItem_Click);
			// 
			// enterDataToolStripMenuItem
			// 
			this->enterDataToolStripMenuItem->Name = L"enterDataToolStripMenuItem";
			this->enterDataToolStripMenuItem->Size = System::Drawing::Size(137, 22);
			this->enterDataToolStripMenuItem->Text = L"Enter Data";
			this->enterDataToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::enterDataToolStripMenuItem_Click);
			// 
			// servoSetupToolStripMenuItem
			// 
			this->servoSetupToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(1) {this->setupToolStripMenuItem});
			this->servoSetupToolStripMenuItem->Name = L"servoSetupToolStripMenuItem";
			this->servoSetupToolStripMenuItem->Size = System::Drawing::Size(75, 20);
			this->servoSetupToolStripMenuItem->Text = L"ServoSetup";
			// 
			// setupToolStripMenuItem
			// 
			this->setupToolStripMenuItem->Name = L"setupToolStripMenuItem";
			this->setupToolStripMenuItem->Size = System::Drawing::Size(113, 22);
			this->setupToolStripMenuItem->Text = L"Setup";
			this->setupToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::setupToolStripMenuItem_Click);
			// 
			// aToolStripMenuItem
			// 
			this->aToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(1) {this->forVelocityaccelerationdistanceToolStripMenuItem});
			this->aToolStripMenuItem->Name = L"aToolStripMenuItem";
			this->aToolStripMenuItem->Size = System::Drawing::Size(79, 20);
			this->aToolStripMenuItem->Text = L"Adjustments";
			// 
			// forVelocityaccelerationdistanceToolStripMenuItem
			// 
			this->forVelocityaccelerationdistanceToolStripMenuItem->Name = L"forVelocityaccelerationdistanceToolStripMenuItem";
			this->forVelocityaccelerationdistanceToolStripMenuItem->Size = System::Drawing::Size(261, 22);
			this->forVelocityaccelerationdistanceToolStripMenuItem->Text = L"Velocity,Acceleration,Distance,Shots";
			this->forVelocityaccelerationdistanceToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::forVelocityaccelerationdistanceToolStripMenuItem_Click);
			// 
			// groupBox1
			// 
			this->groupBox1->BackColor = System::Drawing::Color::Gainsboro;
			this->groupBox1->Controls->Add(this->label18);
			this->groupBox1->Controls->Add(this->label17);
			this->groupBox1->Controls->Add(this->pictureBox3);
			this->groupBox1->Controls->Add(this->label14);
			this->groupBox1->Controls->Add(this->label7);
			this->groupBox1->Controls->Add(this->label6);
			this->groupBox1->Controls->Add(this->label5);
			this->groupBox1->Controls->Add(this->label3);
			this->groupBox1->Controls->Add(this->label1);
			this->groupBox1->Location = System::Drawing::Point(676, 499);
			this->groupBox1->Name = L"groupBox1";
			this->groupBox1->Size = System::Drawing::Size(222, 221);
			this->groupBox1->TabIndex = 65;
			this->groupBox1->TabStop = false;
			this->groupBox1->Text = L"INFO";
			// 
			// label18
			// 
			this->label18->AutoSize = true;
			this->label18->Location = System::Drawing::Point(183, 16);
			this->label18->Name = L"label18";
			this->label18->Size = System::Drawing::Size(16, 13);
			this->label18->TabIndex = 8;
			this->label18->Text = L"...";
			// 
			// label17
			// 
			this->label17->AutoSize = true;
			this->label17->Location = System::Drawing::Point(147, 16);
			this->label17->Name = L"label17";
			this->label17->Size = System::Drawing::Size(33, 13);
			this->label17->TabIndex = 7;
			this->label17->Text = L"Timer";
			// 
			// pictureBox3
			// 
			this->pictureBox3->Location = System::Drawing::Point(22, 60);
			this->pictureBox3->Name = L"pictureBox3";
			this->pictureBox3->Size = System::Drawing::Size(180, 150);
			this->pictureBox3->TabIndex = 0;
			this->pictureBox3->TabStop = false;
			// 
			// label14
			// 
			this->label14->AutoSize = true;
			this->label14->Location = System::Drawing::Point(56, 42);
			this->label14->Name = L"label14";
			this->label14->Size = System::Drawing::Size(16, 13);
			this->label14->TabIndex = 6;
			this->label14->Text = L"...";
			// 
			// label7
			// 
			this->label7->AutoSize = true;
			this->label7->Location = System::Drawing::Point(56, 29);
			this->label7->Name = L"label7";
			this->label7->Size = System::Drawing::Size(16, 13);
			this->label7->TabIndex = 5;
			this->label7->Text = L"...";
			// 
			// label6
			// 
			this->label6->AutoSize = true;
			this->label6->Location = System::Drawing::Point(56, 16);
			this->label6->Name = L"label6";
			this->label6->Size = System::Drawing::Size(16, 13);
			this->label6->TabIndex = 4;
			this->label6->Text = L"...";
			// 
			// label5
			// 
			this->label5->AutoSize = true;
			this->label5->Location = System::Drawing::Point(6, 42);
			this->label5->Name = L"label5";
			this->label5->Size = System::Drawing::Size(26, 13);
			this->label5->TabIndex = 3;
			this->label5->Text = L"Age";
			// 
			// label3
			// 
			this->label3->AutoSize = true;
			this->label3->Location = System::Drawing::Point(6, 29);
			this->label3->Name = L"label3";
			this->label3->Size = System::Drawing::Size(47, 13);
			this->label3->TabIndex = 2;
			this->label3->Text = L"Barcode";
			// 
			// label1
			// 
			this->label1->AutoSize = true;
			this->label1->Location = System::Drawing::Point(6, 16);
			this->label1->Name = L"label1";
			this->label1->Size = System::Drawing::Size(35, 13);
			this->label1->TabIndex = 1;
			this->label1->Text = L"Name";
			// 
			// groupBox3
			// 
			this->groupBox3->BackColor = System::Drawing::Color::Gainsboro;
			this->groupBox3->Controls->Add(this->button9);
			this->groupBox3->Controls->Add(this->button8);
			this->groupBox3->Controls->Add(this->button6);
			this->groupBox3->Location = System::Drawing::Point(676, 36);
			this->groupBox3->Name = L"groupBox3";
			this->groupBox3->Size = System::Drawing::Size(221, 66);
			this->groupBox3->TabIndex = 66;
			this->groupBox3->TabStop = false;
			// 
			// splitter1
			// 
			this->splitter1->Location = System::Drawing::Point(0, 24);
			this->splitter1->Name = L"splitter1";
			this->splitter1->Size = System::Drawing::Size(3, 708);
			this->splitter1->TabIndex = 70;
			this->splitter1->TabStop = false;
			// 
			// groupBox6
			// 
			this->groupBox6->Controls->Add(this->numericUpDown5);
			this->groupBox6->Controls->Add(this->label15);
			this->groupBox6->Controls->Add(this->numericUpDown4);
			this->groupBox6->Controls->Add(this->label4);
			this->groupBox6->Controls->Add(this->numericUpDown3);
			this->groupBox6->Controls->Add(this->label2);
			this->groupBox6->Controls->Add(this->label30);
			this->groupBox6->Controls->Add(this->numericUpDown7);
			this->groupBox6->Controls->Add(this->numericUpDown10);
			this->groupBox6->Controls->Add(this->label32);
			this->groupBox6->Location = System::Drawing::Point(12, 622);
			this->groupBox6->Name = L"groupBox6";
			this->groupBox6->Size = System::Drawing::Size(658, 47);
			this->groupBox6->TabIndex = 71;
			this->groupBox6->TabStop = false;
			this->groupBox6->Text = L"QUICK SETTINGS";
			// 
			// numericUpDown5
			// 
			this->numericUpDown5->Location = System::Drawing::Point(457, 16);
			this->numericUpDown5->Maximum = System::Decimal(gcnew cli::array< System::Int32 >(4) {1000, 0, 0, 0});
			this->numericUpDown5->Name = L"numericUpDown5";
			this->numericUpDown5->Size = System::Drawing::Size(55, 20);
			this->numericUpDown5->TabIndex = 68;
			this->numericUpDown5->Value = System::Decimal(gcnew cli::array< System::Int32 >(4) {20, 0, 0, 0});
			this->numericUpDown5->ValueChanged += gcnew System::EventHandler(this, &Form1::numericUpDown5_ValueChanged);
			// 
			// label15
			// 
			this->label15->AutoSize = true;
			this->label15->Location = System::Drawing::Point(412, 21);
			this->label15->Name = L"label15";
			this->label15->Size = System::Drawing::Size(33, 13);
			this->label15->TabIndex = 67;
			this->label15->Text = L"Timer";
			// 
			// numericUpDown4
			// 
			this->numericUpDown4->Location = System::Drawing::Point(351, 16);
			this->numericUpDown4->Name = L"numericUpDown4";
			this->numericUpDown4->Size = System::Drawing::Size(55, 20);
			this->numericUpDown4->TabIndex = 66;
			this->numericUpDown4->ValueChanged += gcnew System::EventHandler(this, &Form1::numericUpDown4_ValueChanged);
			// 
			// label4
			// 
			this->label4->AutoSize = true;
			this->label4->Location = System::Drawing::Point(252, 21);
			this->label4->Name = L"label4";
			this->label4->Size = System::Drawing::Size(93, 13);
			this->label4->TabIndex = 65;
			this->label4->Text = L"Decrement Bullets";
			// 
			// numericUpDown3
			// 
			this->numericUpDown3->Location = System::Drawing::Point(191, 19);
			this->numericUpDown3->Maximum = System::Decimal(gcnew cli::array< System::Int32 >(4) {100000, 0, 0, 0});
			this->numericUpDown3->Name = L"numericUpDown3";
			this->numericUpDown3->Size = System::Drawing::Size(55, 20);
			this->numericUpDown3->TabIndex = 64;
			this->numericUpDown3->Value = System::Decimal(gcnew cli::array< System::Int32 >(4) {100, 0, 0, 0});
			this->numericUpDown3->ValueChanged += gcnew System::EventHandler(this, &Form1::numericUpDown3_ValueChanged);
			// 
			// label2
			// 
			this->label2->AutoSize = true;
			this->label2->Location = System::Drawing::Point(147, 23);
			this->label2->Name = L"label2";
			this->label2->Size = System::Drawing::Size(38, 13);
			this->label2->TabIndex = 63;
			this->label2->Text = L"Bullets";
			// 
			// numericUpDown2
			// 
			this->numericUpDown2->Location = System::Drawing::Point(163, 16);
			this->numericUpDown2->Maximum = System::Decimal(gcnew cli::array< System::Int32 >(4) {254, 0, 0, 0});
			this->numericUpDown2->Name = L"numericUpDown2";
			this->numericUpDown2->Size = System::Drawing::Size(55, 20);
			this->numericUpDown2->TabIndex = 70;
			this->numericUpDown2->ValueChanged += gcnew System::EventHandler(this, &Form1::numericUpDown2_ValueChanged);
			// 
			// numericUpDown1
			// 
			this->numericUpDown1->Location = System::Drawing::Point(82, 16);
			this->numericUpDown1->Maximum = System::Decimal(gcnew cli::array< System::Int32 >(4) {254, 0, 0, 0});
			this->numericUpDown1->Name = L"numericUpDown1";
			this->numericUpDown1->Size = System::Drawing::Size(55, 20);
			this->numericUpDown1->TabIndex = 1;
			this->numericUpDown1->ValueChanged += gcnew System::EventHandler(this, &Form1::numericUpDown1_ValueChanged);
			// 
			// button7
			// 
			this->button7->BackColor = System::Drawing::Color::White;
			this->button7->Location = System::Drawing::Point(461, 13);
			this->button7->Name = L"button7";
			this->button7->Size = System::Drawing::Size(51, 23);
			this->button7->TabIndex = 69;
			this->button7->Text = L"Bottom";
			this->button7->UseVisualStyleBackColor = false;
			this->button7->Click += gcnew System::EventHandler(this, &Form1::button7_Click);
			// 
			// button5
			// 
			this->button5->BackColor = System::Drawing::Color::White;
			this->button5->Location = System::Drawing::Point(382, 13);
			this->button5->Name = L"button5";
			this->button5->Size = System::Drawing::Size(51, 23);
			this->button5->TabIndex = 68;
			this->button5->Text = L"Top";
			this->button5->UseVisualStyleBackColor = false;
			this->button5->Click += gcnew System::EventHandler(this, &Form1::button5_Click);
			// 
			// button4
			// 
			this->button4->BackColor = System::Drawing::Color::White;
			this->button4->Location = System::Drawing::Point(544, 13);
			this->button4->Name = L"button4";
			this->button4->Size = System::Drawing::Size(51, 23);
			this->button4->TabIndex = 66;
			this->button4->Text = L"Ok";
			this->button4->UseVisualStyleBackColor = false;
			this->button4->Click += gcnew System::EventHandler(this, &Form1::button4_Click);
			// 
			// label34
			// 
			this->label34->AutoSize = true;
			this->label34->Location = System::Drawing::Point(6, 23);
			this->label34->Name = L"label34";
			this->label34->Size = System::Drawing::Size(50, 13);
			this->label34->TabIndex = 65;
			this->label34->Text = L"Callibrate";
			// 
			// button3
			// 
			this->button3->BackColor = System::Drawing::Color::White;
			this->button3->Location = System::Drawing::Point(303, 13);
			this->button3->Name = L"button3";
			this->button3->Size = System::Drawing::Size(51, 23);
			this->button3->TabIndex = 64;
			this->button3->Text = L"Right";
			this->button3->UseVisualStyleBackColor = false;
			this->button3->Click += gcnew System::EventHandler(this, &Form1::button3_Click);
			// 
			// button2
			// 
			this->button2->BackColor = System::Drawing::Color::White;
			this->button2->Location = System::Drawing::Point(224, 13);
			this->button2->Name = L"button2";
			this->button2->Size = System::Drawing::Size(51, 23);
			this->button2->TabIndex = 63;
			this->button2->Text = L"Left";
			this->button2->UseVisualStyleBackColor = false;
			this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);
			// 
			// groupBox4
			// 
			this->groupBox4->Controls->Add(this->pictureBox1);
			this->groupBox4->Location = System::Drawing::Point(12, 108);
			this->groupBox4->Name = L"groupBox4";
			this->groupBox4->Size = System::Drawing::Size(658, 508);
			this->groupBox4->TabIndex = 72;
			this->groupBox4->TabStop = false;
			// 
			// groupBox7
			// 
			this->groupBox7->Controls->Add(this->pictureBox2);
			this->groupBox7->Location = System::Drawing::Point(12, 36);
			this->groupBox7->Name = L"groupBox7";
			this->groupBox7->Size = System::Drawing::Size(658, 66);
			this->groupBox7->TabIndex = 73;
			this->groupBox7->TabStop = false;
			// 
			// pictureBox2
			// 
			this->pictureBox2->BackgroundImage = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"pictureBox2.BackgroundImage")));
			this->pictureBox2->Location = System::Drawing::Point(9, 15);
			this->pictureBox2->Name = L"pictureBox2";
			this->pictureBox2->Size = System::Drawing::Size(639, 45);
			this->pictureBox2->TabIndex = 0;
			this->pictureBox2->TabStop = false;
			// 
			// groupBox5
			// 
			this->groupBox5->Controls->Add(this->button10);
			this->groupBox5->Controls->Add(this->label40);
			this->groupBox5->Controls->Add(this->label39);
			this->groupBox5->Controls->Add(this->label38);
			this->groupBox5->Controls->Add(this->button4);
			this->groupBox5->Controls->Add(this->label37);
			this->groupBox5->Controls->Add(this->button7);
			this->groupBox5->Controls->Add(this->label36);
			this->groupBox5->Controls->Add(this->numericUpDown2);
			this->groupBox5->Controls->Add(this->label35);
			this->groupBox5->Controls->Add(this->button5);
			this->groupBox5->Controls->Add(this->label34);
			this->groupBox5->Controls->Add(this->numericUpDown1);
			this->groupBox5->Controls->Add(this->button3);
			this->groupBox5->Controls->Add(this->button2);
			this->groupBox5->Location = System::Drawing::Point(12, 675);
			this->groupBox5->Name = L"groupBox5";
			this->groupBox5->Size = System::Drawing::Size(658, 47);
			this->groupBox5->TabIndex = 1;
			this->groupBox5->TabStop = false;
			this->groupBox5->Text = L"CALIBRATION";
			// 
			// button10
			// 
			this->button10->Location = System::Drawing::Point(601, 13);
			this->button10->Name = L"button10";
			this->button10->Size = System::Drawing::Size(51, 23);
			this->button10->TabIndex = 72;
			this->button10->Text = L"Reset";
			this->button10->UseVisualStyleBackColor = true;
			this->button10->Click += gcnew System::EventHandler(this, &Form1::button10_Click);
			// 
			// label40
			// 
			this->label40->AutoSize = true;
			this->label40->Location = System::Drawing::Point(143, 23);
			this->label40->Name = L"label40";
			this->label40->Size = System::Drawing::Size(14, 13);
			this->label40->TabIndex = 1;
			this->label40->Text = L"Y";
			// 
			// label39
			// 
			this->label39->AutoSize = true;
			this->label39->Location = System::Drawing::Point(62, 23);
			this->label39->Name = L"label39";
			this->label39->Size = System::Drawing::Size(14, 13);
			this->label39->TabIndex = 71;
			this->label39->Text = L"X";
			// 
			// label38
			// 
			this->label38->AutoSize = true;
			this->label38->Location = System::Drawing::Point(518, 23);
			this->label38->Name = L"label38";
			this->label38->Size = System::Drawing::Size(16, 13);
			this->label38->TabIndex = 4;
			this->label38->Text = L"...";
			// 
			// label37
			// 
			this->label37->AutoSize = true;
			this->label37->Location = System::Drawing::Point(439, 23);
			this->label37->Name = L"label37";
			this->label37->Size = System::Drawing::Size(16, 13);
			this->label37->TabIndex = 3;
			this->label37->Text = L"...";
			// 
			// label36
			// 
			this->label36->AutoSize = true;
			this->label36->Location = System::Drawing::Point(360, 23);
			this->label36->Name = L"label36";
			this->label36->Size = System::Drawing::Size(16, 13);
			this->label36->TabIndex = 2;
			this->label36->Text = L"...";
			// 
			// label35
			// 
			this->label35->AutoSize = true;
			this->label35->Location = System::Drawing::Point(281, 23);
			this->label35->Name = L"label35";
			this->label35->Size = System::Drawing::Size(16, 13);
			this->label35->TabIndex = 1;
			this->label35->Text = L"...";
			// 
			// Form1
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->BackColor = System::Drawing::Color::Gainsboro;
			this->BackgroundImageLayout = System::Windows::Forms::ImageLayout::Center;
			this->ClientSize = System::Drawing::Size(905, 732);
			this->Controls->Add(this->groupBox5);
			this->Controls->Add(this->groupBox3);
			this->Controls->Add(this->groupBox1);
			this->Controls->Add(this->groupBox2);
			this->Controls->Add(this->STATISTICS);
			this->Controls->Add(this->groupBox7);
			this->Controls->Add(this->groupBox4);
			this->Controls->Add(this->groupBox6);
			this->Controls->Add(this->splitter1);
			this->Controls->Add(this->menuStrip1);
			this->DoubleBuffered = true;
			this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedDialog;
			this->MainMenuStrip = this->menuStrip1;
			this->Name = L"Form1";
			this->Text = L"TurretControl";
			this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox1))->EndInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->numericUpDown7))->EndInit();
			this->groupBox2->ResumeLayout(false);
			this->groupBox2->PerformLayout();
			this->STATISTICS->ResumeLayout(false);
			this->STATISTICS->PerformLayout();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->numericUpDown10))->EndInit();
			this->menuStrip1->ResumeLayout(false);
			this->menuStrip1->PerformLayout();
			this->groupBox1->ResumeLayout(false);
			this->groupBox1->PerformLayout();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox3))->EndInit();
			this->groupBox3->ResumeLayout(false);
			this->groupBox6->ResumeLayout(false);
			this->groupBox6->PerformLayout();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->numericUpDown5))->EndInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->numericUpDown4))->EndInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->numericUpDown3))->EndInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->numericUpDown2))->EndInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->numericUpDown1))->EndInit();
			this->groupBox4->ResumeLayout(false);
			this->groupBox7->ResumeLayout(false);
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox2))->EndInit();
			this->groupBox5->ResumeLayout(false);
			this->groupBox5->PerformLayout();
			this->ResumeLayout(false);
			this->PerformLayout();

		}
#pragma endregion



//thread main functions th1
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////


private: System::Void th1Method(){

			 while(1){


iii=1;
#pragma region imagecapture

    if(capture!=NULL)
	{
	cvGrabFrame(capture);
	rez = cvRetrieveFrame( capture );			
	cvResize(rez,img,CV_INTER_LINEAR); 
	img2= cvCloneImage(img);
		
	}

#pragma endregion


#pragma region choice

switch(choice)
{

    case 1: 
	MotionDiff();

    break;

    case 2:
    MotionBack();

    break;

    case 6:
	People();	
      
	break; 

	case 10:
    
    break;
	case 11:
    mean();
    break;

}

#pragma endregion


#pragma region tracker

if(bl>0)
{

switch(tracker)
{

    case 1:
    position(img,rect,cent,bl,&tracx,&tracy,blobnr,tracx,tracy,&recwidth,&recheight);
    rect2.width=recwidth;
    rect2.height=recheight;
	rect2.x=tracx-0.5*recwidth;
	rect2.y=tracy-0.5*recheight;
    break;

    case 2:
	sizeCalc(img,rect,cent,bl,&tracx,&tracy,&recwidth,&recheight);
	rect2.width=recwidth;
    rect2.height=recheight;
	rect2.x=tracx-0.5*recwidth;
	rect2.y=tracy-0.5*recheight;
    break;

    case 3:
	sizesmall(img,rect,cent,bl,&tracx,&tracy,&recwidth,&recheight); 
	rect2.width=recwidth;
    rect2.height=recheight;
	rect2.x=tracx-0.5*recwidth;
	rect2.y=tracy-0.5*recheight;
   
    break;

    case 4:
	random(img,rect,cent,bl,&tracx,&tracy,&recwidth,&recheight); 
	rect2.width=recwidth;
    rect2.height=recheight;
	rect2.x=tracx-0.5*recwidth;
	rect2.y=tracy-0.5*recheight;
   
    break;
	case 5:
	break;

    }
}
#pragma endregion


#pragma region centrexyz	
     					
    label11->Text=Convert::ToString(tracx);	
    label12->Text=Convert::ToString(480-tracy);	
						          
#pragma endregion


#pragma region imagedisplay
	
    if(checkBox1->Checked==true && capture!=NULL)
	{
				
	cvReleaseImage(&img); 
	img= cvCloneImage(img2);

	if(bl>0){
	cvCircle(img, cvPoint(tracx-(0.5*(rect2.width)-25),tracy+(0.5*(rect2.height)+10)),4,cvScalar(50,255,50,5),2);
	//cvCircle(img, cvPoint(tracx,tracy),10,cvScalar(50,255,50,5),6);
	}


	if(checkBox4->Checked==true)
	{
	 cvCircle(img, cvPoint(track_boxf.center.x,track_boxf.center.y),4,cvScalar(50,255,50,5),2);
	 // cvEllipseBox( img, track_boxf, CV_RGB(0,255,0), 2, CV_AA, 0 );
	}

    showmultiple(img,rect,cent,bl);

	}		

	this->pictureBox1->Image=(gcnew 
    System::Drawing::Bitmap(img->width,img->height,img->widthStep, 
    System::Drawing::Imaging::PixelFormat::Format24bppRgb,(System::IntPtr)img->imageData)); 
#pragma endregion

  

  
    
    cvReleaseImage(&img2);
	motion_=bl;
    bl=0;
    iii=0;
    Thread::Sleep(30);
	}
}


//Servo thread th2////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

 private: System::Void th2Method()
{
	int runthrough=0;
	int bull_=0;
	int count_=0;
	int adjustx=0;
	int adjusty=0;
	int acelx=0;
	int acely=0;
	int time_=0;
	int velx_[2];
	int vely_[2];
	int xc[2];
	int yc[2];
	int acc=0;
	int xuse=0;
	int yuse=0;
    int xp_=0;
	int yp_=0;

array<unsigned char>^ data1 = gcnew array<unsigned char>(3); 
array<unsigned char>^ data2 = gcnew array<unsigned char>(3); 
array<unsigned char>^ data3 = gcnew array<unsigned char>(3); 
	
    while(1)
	{

	if(checkBox3->Checked==true )
	{
	if(checkBox4->Checked==true)
	{
		xuse=track_boxf.center.x;
		yuse=track_boxf.center.y;

	}
	else
	{
		xuse=tracx;
		yuse=tracy;

	}

if(checkBox6->Checked==true)
{
	if(time_==0)
    {
		xc[time_]=xuse;
		yc[time_]=yuse;
		velx_[time_]=xc[0]-xc[1];
		vely_[time_]=yc[0]-yc[1];
		acelx=velx_[0]-velx_[1];
		acely=vely_[0]-vely_[1];
	   
		label29->Text=Convert::ToString(velx_[time_]);
		label27->Text=Convert::ToString(vely_[time_]);
		label44->Text=Convert::ToString(acelx);
		label45->Text=Convert::ToString(acely);

    adjustx=factorx_*(velx_[time_]+0.5*acelx);
	adjusty=factory_*(vely_[time_]+0.5*acely);

	xuse=xuse+adjustx;
	yuse=yuse+adjusty+addtoY;

		 time_=1;
     }
    else
     {
		 xc[time_]=xuse;
		 yc[time_]=yuse;
		 velx_[time_]=xc[1]-xc[0];
		 vely_[time_]=yc[1]-yc[0];
	     acelx=velx_[1]-velx_[0];
		 acely=vely_[1]-vely_[0];
	    
		label29->Text=Convert::ToString(velx_[time_]);
		label27->Text=Convert::ToString(vely_[time_]);
		label44->Text=Convert::ToString(acelx);
		label45->Text=Convert::ToString(acely);

    adjustx=factorx_*(velx_[time_]+0.5*acelx);
	adjusty=factory_*(vely_[time_]+0.5*acely);

	xuse=xuse+adjustx;
	yuse=yuse+adjusty+addtoY;

		 time_=0;
     }


}   
     //For x postition
     data1[0] = 255;
     data1[1] = servnrx_; 		
	
     xp_=(-xuse)/scale1-offset1;	 
     data1[2] = xp_; 
		
     //For y position
	 data2[0] = 255;
     data2[1] = servnry_; 
	
	 yp_=((480-yuse))/scale2+offset2;
     data2[2] = yp_; 


if(stopt_==false)
{
if(checkBox5->Checked==true)
{

	 //For Trigger
	 data3[0] = 255;
     data3[1] = servnrt_; 


	 switch(trigchoice_)
	 {
    case 1:
if(bullet_>0)
{
     if(trig_==true)
	 {
     data3[2] = trigra1_; 
	 bull_=1;
	 }
	 if(trig_==false)
	 {
     data3[2] = trigra2_;
	 if(bull_==1)
	 {
	 bullet_=bullet_-decrease_;
	  bull_=0;
	 }
	
	 }
}
	break;

	case 2:
if(motion_>0)
{
	runthrough=1;
}

if(runthrough>0 && bullet_>0)
{
    count_++;

	if(count_==1*speedchoice_)
	{
		 data3[2] = trigra1_; 
	}
	if(count_==2*speedchoice_)
	{
		 data3[2] = trigra2_; 
		  bullet_=bullet_-decrease_;
	}
	if(count_==3*speedchoice_)
	{
		 data3[2] = trigra1_; 
	}
	if(count_==4*speedchoice_)
	{
		 data3[2] = trigra2_; 
		  bullet_=bullet_-decrease_;
	}
	if(count_==5*speedchoice_)
	{
		 data3[2] = trigra1_; 
	}
	if(count_==6*speedchoice_)
	{
		 data3[2] = trigra2_; 
		  bullet_=bullet_-decrease_;
	}
    if(count_>=12*speedchoice_)
	{
		count_=0;
		runthrough=0;
	}

}
	break;

	case 3:

if(motion_>0)
{
	runthrough=1;
}

		if(runthrough>0 && bullet_>0)
		{
    count_++;
    if(count_==1*speedchoice_)
	{
		 data3[2] = trigra1_; 
	}
	if(count_>=2*speedchoice_)
	{
		 data3[2] = trigra2_;
		  bullet_=bullet_-decrease_;
		 count_=0;
		 runthrough=0;
	}
		}
	break;


    case 4:
if(bullet_>0 && motion_>0)
{
  data3[2] = trigra1_; 
  bullet_=bullet_-decrease_;
}
else
{
	data3[2] = trigra2_;
}
	break;
	 }
   
	 serialPort1->Write(data3, 0, 3);
}
}
     serialPort1->Write(data1, 0, 3);
	 serialPort1->Write(data2, 0, 3);

}
    

	label46->Text=Convert::ToString(bullet_);
	
	Thread::Sleep(25);
	}
}



///security thread//////////////////////////////////////////
///////////////////////////////////////////////////////////////
private: System::Void th3Method(){


			 int kk=0;
while(1)
{
	ident_=0;
  waitth3_=1;
  if(capture3!=NULL)
	{
	cvGrabFrame(capture3);
	rez2 = cvRetrieveFrame( capture3 );			
	 
 
	

switch(securitychoice)
{
case 1:
	face();
	break;

case 2:
    Bar();
	break;
}

if(ident_==1)
{
	countdown2_=countdown_;
	stopt_=1;
}
if(countdown2_>0)
{
	countdown2_=countdown2_-1;
}
if(countdown2_==0)
{
	stopt_=0;
}

if(img4!=NULL)
{
    this->pictureBox3->Image=(gcnew 
    System::Drawing::Bitmap(img4->width,img4->height,img4->widthStep, 
    System::Drawing::Imaging::PixelFormat::Format24bppRgb,(System::IntPtr)img4->imageData)); 
}
  }

label18->Text=Convert::ToString(countdown2_);
waitth3_=0;
Thread::Sleep(200);
}
		 }




//Settings
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////


private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {

			 left_=(Convert::ToInt32(numericUpDown1->Value));
			 label35->Text="Ok";
		 }
private: System::Void button3_Click(System::Object^  sender, System::EventArgs^  e) {
			  right_=(Convert::ToInt32(numericUpDown1->Value));
			  label36->Text="Ok";
		 }
private: System::Void button5_Click(System::Object^  sender, System::EventArgs^  e) {
			   top_=(Convert::ToInt32(numericUpDown2->Value));
			   label37->Text="Ok";
		 }
private: System::Void button7_Click(System::Object^  sender, System::EventArgs^  e) {

		  bot_=(Convert::ToInt32(numericUpDown2->Value));
		  label38->Text="Ok";
		 }
private: System::Void button4_Click(System::Object^  sender, System::EventArgs^  e) {


			 scale1=(640/(right_-left_));
			 scale2=(480/(top_-bot_));
			 offset1=left_;
			 offset2=bot_;

			 label35->Text="...";
			 label36->Text="...";
			 label37->Text="...";
			 label38->Text="...";
		 }
private: System::Void numericUpDown1_ValueChanged(System::Object^  sender, System::EventArgs^  e) {
		 tracx=(Convert::ToInt32(numericUpDown1->Value));
		 }
private: System::Void numericUpDown2_ValueChanged(System::Object^  sender, System::EventArgs^  e) {
			 tracy=480-((Convert::ToInt32(numericUpDown2->Value)));
		 }


private: System::Void button10_Click(System::Object^  sender, System::EventArgs^  e) {

		     scale1=1;
			 scale2=1;
			 offset1=0;
			 offset2=0;
		 }
private: System::Void button11_Click(System::Object^  sender, System::EventArgs^  e) {
			 	 reset_();
		 }


private: System::Void textBox1_TextChanged(System::Object^  sender, System::EventArgs^  e) {
			 

}
		 



private: System::Void button6_Click(System::Object^  sender, System::EventArgs^  e) {
    if(flag_==0)
    {
    th1->Resume();
	}
	if(flag_==0)
	{
	th2->Resume();
	}
	  if(flag3_==0)
    {
    th3->Resume();
	}
			// Close();
    Application::Exit();

}


private: System::Void button9_Click(System::Object^  sender, System::EventArgs^  e) {



    if(flag_==0){
		
    capture = cvCaptureFromCAM( camp1_ );
    // cvSetCaptureProperty( capture, CV_CAP_PROP_FRAME_WIDTH, 640 );
    // cvSetCaptureProperty( capture, CV_CAP_PROP_FRAME_HEIGHT, 480 );

    th1->Resume();	
	th2->Resume();
	
	flag_=1;
	}

 }


private: System::Void button8_Click(System::Object^  sender, System::EventArgs^  e) {


if(iii==0 && flag_==1)
{
	th1->Suspend();
    th2->Suspend();
	cvReleaseCapture(&capture);


   

	flag_=0;
	

}
}


private: System::Void numericUpDown10_ValueChanged(System::Object^  sender, System::EventArgs^  e) {

    blobnr=Convert::ToInt32(numericUpDown10->Value);
	tracx=cent[blobnr].x;
	tracy=cent[blobnr].y;
}


private: System::Void comboBox1_SelectedIndexChanged(System::Object^  sender, System::EventArgs^  e) {

 
    

    if(comboBox1->Text=="MotionDifference")
	{
	choice=1;
	tracker=1;
	}
	if(comboBox1->Text=="MotionBackground")
	{
	choice=2;
	tracker=1;
	}


	
	if(comboBox1->Text=="People")
	{
	choice=6;
	tracker=5;
	}



	if(comboBox1->Text=="Mouse")
	{
	choice=10;
	tracker=5;
	}
	
	if(comboBox1->Text=="ColourHist")
	{
	choice=11;
	tracker=1;
	backp_=1;
	}
		 
}
private: System::Void comboBox5_SelectedIndexChanged(System::Object^  sender, System::EventArgs^  e) {

	if(comboBox5->Text=="Face")
	{
	securitychoice=1;

	}

	if(comboBox5->Text=="Barcode")
	{
	securitychoice=2;
	
	}
		 }

private: System::Void comboBox2_SelectedIndexChanged(System::Object^  sender, System::EventArgs^  e) {
    if(comboBox2->Text=="Follow")
	{
	tracker=1;
	}
	if(comboBox2->Text=="Biggest")
	{
	tracker=2;
	}
	if(comboBox2->Text=="Smallest")
	{
	tracker=3;
	}
	if(comboBox2->Text=="Random")
	{
	tracker=4;
	}

}
		 private: System::Void comboBox3_SelectedIndexChanged(System::Object^  sender, System::EventArgs^  e) {


    if(comboBox3->Text=="Mouse")
	{
	trigchoice_=1;
	}
	if(comboBox3->Text=="Burst")
	{
	trigchoice_=2;
	}
	if(comboBox3->Text=="Rapid")
	{
	trigchoice_=3;
	}
	if(comboBox3->Text=="Hold")
	{
	trigchoice_=4;
	}




		 }
private: System::Void comboBox4_SelectedIndexChanged(System::Object^  sender, System::EventArgs^  e) {


    if(comboBox4->Text=="Slow")
	{
	speedchoice_=10;
	}
	if(comboBox4->Text=="Medium")
	{
	speedchoice_=5;
	}
	if(comboBox4->Text=="Fast")
	{
	speedchoice_=2;
	}


		 }

private: System::Void changeSettingsToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
	
 
	
		 
	
	
	settings^ dialog = gcnew settings();
    if(dialog->ShowDialog() == System::Windows::Forms::DialogResult::OK)
    {
	threshold1=dialog->thresholdbar;
	
    camp1_=dialog->camport1_; 
    camp2_=dialog->camport2_; 
    perim_=dialog->sensit_;
	vmi_=dialog->vmin_;
	vma_=dialog->vmax_;
	smi_=dialog->smin_;
    // capture = cvCaptureFromCAM( 0 );
    //timer1->Start();
	 			
    }				

 }


private: System::Void enterDataToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {

  
	if(iii==0)
    {
	if(flag_==1)
	{
	th1->Suspend();
    th2->Suspend();
	flag_=0;
	}
	cvReleaseCapture(&capture);
	

	Ident^ ident = gcnew Ident();
    if(ident->ShowDialog() == System::Windows::Forms::DialogResult::OK)
    {
    capture = cvCaptureFromCAM( 0 );
	if(flag_==0)
	{
    th1->Resume();
    th2->Resume();
	flag_=1;
	}		
	}
	}
}
private: System::Void setupToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {

    Servo^ serv_ = gcnew Servo();
    if(serv_->ShowDialog() == System::Windows::Forms::DialogResult::OK)
    {
		trigra1_=serv_->trigr1_;
		trigra2_=serv_->trigr2_;

    servnrx_=serv_->servox;
    servnry_=serv_->servoy;
    servnrt_=serv_->servot;		
	offset1=serv_->offset_;
	scale1=serv_->scale_;
	offset2=serv_->offsety_;
	scale2=serv_->scaley_;
    }			
}
private: System::Void forVelocityaccelerationdistanceToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {

			 Adjustments^ adj_ = gcnew Adjustments();
    if(adj_->ShowDialog() == System::Windows::Forms::DialogResult::OK)
    {
    factorx_=adj_->facx_;
    factory_=adj_->facy_;
	    addtoY=adj_->addy_;
		bullet_=adj_->bullets_;
		decrease_=adj_->decrement_;
   
    }	

		 }

private: System::Void checkBox2_CheckedChanged(System::Object^  sender, System::EventArgs^  e) {
	
		 }
//Empty
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
    	 }

private: System::Void groupBox2_Enter(System::Object^  sender, System::EventArgs^  e) {
		 }
private: System::Void groupBox3_Enter(System::Object^  sender, System::EventArgs^  e) {
		 }
private: System::Void checkBox1_CheckedChanged(System::Object^  sender, System::EventArgs^  e) {
		 }
private: System::Void numericUpDown7_ValueChanged(System::Object^  sender, System::EventArgs^  e) {
		 }

private: System::Void dataToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
		 }
private: System::Void settingsToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
		 }
private: System::Void checkBox4_CheckedChanged(System::Object^  sender, System::EventArgs^  e) {
		 }

//Mouse Handlers////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

private: System::Void pictureBox1_Mouse_Move(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e)

{

if(go_==false)
{
	drawx_=e->X;
	drawy_=e->Y;
}

if(choice==10)
{
	tracx=e->X;
	tracy=e->Y;
}

}
private: System::Void pictureBox1_Mouse_Down(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e)

{
	if(trig_==true)
	{
	xrect=e->X;
	yrect=e->Y;
	tracker_=-1;
	go_=1;
	}
	if(trig_==false)
	{
	xrect2=e->X;
	yrect2=e->Y;
	go_=0;
	}


	if(xrect!=xrect2 && yrect!=yrect2)
	{
	rect3.width=fabs(double(xrect-xrect2));
	rect3.height=fabs(double(yrect-yrect2));
    rect3.x=(xrect+xrect2)/2-0.5*(rect3.width);
	rect3.y=(yrect+yrect2)/2-0.5*(rect3.height);
	}
	

    trig_= !trig_;

}






private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {


			  if(rect2.width!=0 && rect2.height!=0)
			  {

			  track_windowf=rect2;
              if(rect2.x<0)
			  {
			  track_windowf.x=0;
			  }
			  if(rect2.x>640)
			  {
			  track_windowf.x=640;
			  }
			  if(rect2.y>480)
			  {
			  track_windowf.y=480;
			  }
              if(rect2.y<0)
			  {
			  track_windowf.y=0;
			  }
               
              if(rect2.x+rect2.width>640)
			  {
				  track_windowf.width=640-rect2.x;
			  }
			   if(rect2.y+rect2.height>480)
			  {
				  track_windowf.height=480-rect2.y;
			  }
             

               
			  }
		 }


//Functions
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
void MotionBack()
{

    if (times==0)
	{
	initialise();
	times=1;
	}
	if(img!=NULL)
	{
	code(img,&progress_);
	} 
    progressBar1->Value=progress_;
    cvSplit (img, split, 0, 0, 0);


	if(checkBox4->Checked==true)
	{
	  cvCamShift( split, track_windowf,
      cvTermCriteria( CV_TERMCRIT_EPS | CV_TERMCRIT_ITER, 10, 1 ),
      &track_compf, &track_boxf );
	  track_windowf = track_compf.rect;

	  cvCircle(img, cvPoint(track_boxf.center.x,track_boxf.center.y),4,cvScalar(50,255,50,5),2);
	}

    bl=Convert::ToInt32(numericUpDown7->Value);//bl = p this is the blobs it should return
    find_connected_components(split,1,perim_,p,rect,cent);
    label22->Text=Convert::ToString(bl);
	showmultiple(img,rect,cent,bl);
}


void MotionDiff()
{
	 
	 update_mhi( img, img, threshold1 );

     cvSplit (img, split, 0, 0, 0);

	if(checkBox4->Checked==true)
	{
	  cvCamShift( split, track_windowf,
      cvTermCriteria( CV_TERMCRIT_EPS | CV_TERMCRIT_ITER, 10, 1 ),
      &track_compf, &track_boxf );
	  track_windowf = track_compf.rect;

	  cvCircle(img, cvPoint(track_boxf.center.x,track_boxf.center.y),4,cvScalar(50,255,50,5),2);
	}

     bl=Convert::ToInt32(numericUpDown7->Value);//bl = p this is the blobs it should return
     find_connected_components(split,1,perim_,p,rect,cent);

	
	
	 //System::Windows::Forms::Control::CheckForIllegalCrossThreadCalls = false; 
     label22->Text=Convert::ToString(bl);	
	 //System::Windows::Forms::Control::CheckForIllegalCrossThreadCalls = true;
	

	 showmultiple(img,rect,cent,bl);
}











void Bar()
{
    char namen[16];
	char* namel=&namen[0];
    int agel=0;
    int codel=0;
    int bcodel=0;
    codel=bar(rez2,threshold1);
    char bcodell[30];

    calcbarc(&agel,&bcodel,codel,namel);

    String^ clistr = gcnew String(namel);
             
    label6->Text=clistr; 
    label7->Text=Convert::ToString(bcodel);	
	label14->Text=Convert::ToString(agel);		

    sprintf(bcodell,"Ident/%d.jpg",bcodel); 
	     
    
    cvReleaseImage(&img7);
	img7=0;
	img7 = cvLoadImage( bcodell,-1 );
	 

	if(img7!=NULL)	
	{
    cvResize(img7,img4,CV_INTER_LINEAR);
	ident_=1;
	
	}
	else
	{
	cvResize(rez2,img4,CV_INTER_LINEAR);
	ident_=0;
	}
	
			
}

void People()
{
	people(img);
}

void face()
{	
   detectAndDraw(rez2,&ident_);
   cvResize(rez2,img4,CV_INTER_LINEAR);
}



void mean()
{

	if(go_==true)
	{
	mean_(img,rect3,tracker_,backp_,vmi_,vma_,smi_);	
	tracker_=1;
	
 
    cvSplit (img, split, 0, 0, 0);


		if(checkBox4->Checked==true)
	{
	  cvCamShift( split, track_windowf,
      cvTermCriteria( CV_TERMCRIT_EPS | CV_TERMCRIT_ITER, 10, 1 ),
      &track_compf, &track_boxf );
	  track_windowf = track_compf.rect;

	 cvCircle(img, cvPoint(track_boxf.center.x,track_boxf.center.y),4,cvScalar(50,255,50,5),2);
	}

    bl=Convert::ToInt32(numericUpDown7->Value);//bl = p this is the blobs it should return
    find_connected_components(split,1,perim_,p,rect,cent);
    label22->Text=Convert::ToString(bl);
	showmultiple(img,rect,cent,bl);


	}
	else
	{
		

cvLine(img,cvPoint(xrect2,yrect2),cvPoint(xrect2,drawy_),cvScalar(255,0,0),2);//square
cvLine(img,cvPoint(xrect2,yrect2),cvPoint(drawx_,yrect2),cvScalar(255,0,0),2);//square
cvLine(img,cvPoint(drawx_,yrect2),cvPoint(drawx_,drawy_),cvScalar(255,0,0),2);//square
cvLine(img,cvPoint(xrect2,drawy_),cvPoint(drawx_,drawy_),cvScalar(255,0,0),2);//square

	}
}











private: System::Void numericUpDown3_ValueChanged(System::Object^  sender, System::EventArgs^  e) {
 bullet_=(Convert::ToInt32(numericUpDown3->Value));
		 }
private: System::Void numericUpDown4_ValueChanged(System::Object^  sender, System::EventArgs^  e) {
			  decrease_=(Convert::ToInt32(numericUpDown4->Value));
		 }

private: System::Void button12_Click(System::Object^  sender, System::EventArgs^  e) {


			
if(flag3_==0)
{
    capture3 = cvCaptureFromCAM( camp2_ );
    // cvSetCaptureProperty( capture, CV_CAP_PROP_FRAME_WIDTH, 640 );
    // cvSetCaptureProperty( capture, CV_CAP_PROP_FRAME_HEIGHT, 480 );

    th3->Resume();	
	flag3_=1;
}
	

	

		 }
private: System::Void button13_Click(System::Object^  sender, System::EventArgs^  e) {

	if(flag3_==1 && waitth3_==0)	
	{
	th3->Suspend();
	cvReleaseCapture(&capture3);
	flag3_=0;
	}
		 }
private: System::Void numericUpDown5_ValueChanged(System::Object^  sender, System::EventArgs^  e) {
			 countdown_=(Convert::ToInt32(numericUpDown5->Value));
		 }
};
}

 